﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ERPStudio;
using System.Data.SqlClient;

namespace Fares
{
    public partial class StocuriFrm : FrmRezumat
    {
        private int IDArticol=-1;
        private DateTime LaData = DateTime.Now;
        private Boolean FolosesteVarianta = false;
        private String Filtru = String.Empty;
        private Decimal CantiateConsumata = -1;

        public StocuriFrm(ModuleClass mc, int iDArticol, DateTime laData, String DenArticol,Decimal cantitate):base(mc)
        {
            InitializeComponent();
            workConnString = mc.workConnectionString;
            IDArticol = iDArticol;
            LaData = laData;
            DenumireL.Text = DenArticol;
            CantiateConsumata = cantitate;

        }

        private void StocuriFrm_Load(object sender, EventArgs e)
        {
            SqlConnection con = DeschideConexiune(workConnString);
            articoleVarianteTableAdapter.Connection = con;
            articoleVarianteTableAdapter.FillByIDArticol(this.eSRPDataSet.ArticoleVariante, IDArticol);
            this.fares_viewStocCurentTableAdapter.Connection = con;
            this.fares_viewStocCurentTableAdapter.Fill(this.eSRPDataSet.fares_viewStocCurent);

            Object retObj = GetSetupValue("FaresSetup", "FolosesteVarinata", ModuleInfo.CodUnitate, con);
            if (retObj != null && retObj != DBNull.Value)
                FolosesteVarianta = Convert.ToBoolean(retObj);
            variantaColumn.Visible = FolosesteVarianta;


            InchideConexiune(con);

            if (IDArticol != -1)
                Filtru = "IDArticol=" + IDArticol.ToString();
            AddBindingSource(fares_viewStocCurentBindingSource);
            AddTableAdaptor(fares_viewStocCurentTableAdapter.Adapter);

            fares_viewStocCurentBindingSource.Filter = Filtru + "AND Stoc<>0";
            fares_viewStocCurentBindingSource.Sort = "";

            if (CantiateConsumata != -1)
            {
                foreach (DataGridViewRow dr in fares_viewStocCurentDGV.Rows)
                {

                }
            }



        }

        private void StocZeroCB_CheckedChanged(object sender, EventArgs e)
        {
            fares_viewStocCurentBindingSource.Filter = StocZeroCB.Checked ? Filtru : Filtru != String.Empty ? Filtru + " AND Stoc<>0" : "Stoc<>0";
        }
    }
}
